package com.cheng.example.book.advise151.chap3.client47;


import java.util.Objects;

/**
 *
 */
public class Employee extends Person {
    private int id;


    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    public Employee(String _name, int _id) {
        super(_name);
        id = _id;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }



    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null || obj.getClass() != this.getClass()) return false;
        if (!super.equals(obj)) return false;
        Employee e = (Employee) obj;
        return Objects.equals(id, e.getId());
    }



}

class Person {
    private String name;

    public Person(String _name) {
        name = _name;
    }

    public String getName() {
        return name;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(name, person.name);
    }



    public static void main(String[] args) {
        Employee e1 = new Employee("张三", 100);
        Employee e2 = new Employee("张三", 100);
//        Person p1 = new Person("张三");
//        System.out.println(p1.equals(e1));
//        System.out.println(p1.equals(e2));
        System.out.println(e1.equals(e2));
    }
}